

#include "atomic_op_asm.h"

#ifdef _ARM_ARCH_6
ENTRY_NP(_atomic_swap_16)
	mov	ip, r0
1:
	ldrexh	r0, [ip]
	strexh	r3, r1, [ip]
	cmp	r3, #0
	bne	1b
#ifdef _ARM_ARCH_7
	dmb
#else
	mcr	p15, 0, ip, c7, c10, 5	/* data memory barrier */
#endif
	RET
END(_atomic_swap_16)

ATOMIC_OP_ALIAS(atomic_swap_16,_atomic_swap_16)
ATOMIC_OP_ALIAS(atomic_swap_short,_atomic_swap_16)
ATOMIC_OP_ALIAS(atomic_swap_ushort,_atomic_swap_16)
CRT_ALIAS(__sync_lock_test_and_set_2,_atomic_swap_16)
CRT_ALIAS(__atomic_exchange_2,_atomic_swap_16)
STRONG_ALIAS(_atomic_swap_short,_atomic_swap_16)
STRONG_ALIAS(_atomic_swap_ushort,_atomic_swap_16)

#if (!defined(_KERNEL) || !defined(_RUMPKERNEL)) && !defined(_STANDALONE)
ENTRY_NP(__sync_lock_release_2)
	mov	r1, #0
	strh	r1, [r0]
	RET
END(__sync_lock_release_2)
#endif
#endif /* _ARM_ARCH_6 */
